<template>
    <van-nav-bar title="搜素页" left-text="返回" left-arrow @click-left="() => { $router.push('/') }" fixed />
    <div style="height: 50px;"></div>
    <van-search v-model="searchval" shape="round" background="#4fc08d" placeholder="请输入搜索关键词" @click="search" />

    <!-- 无数据 -->
    <template v-if="searchval.length == 0 || searchDate.length === 0">
        <van-empty description="描述文字" />
    </template>
    <!-- 有数据 -->
    <template v-else>
        <van-cell-group v-for="item in searchDate">
            <router-link :to="'/detail/'+item.goods_id">
                <van-cell :title="item.goods_name"  />
            </router-link>
            
        </van-cell-group>
    </template>
</template>

<script setup>
import { ref, watch } from 'vue'
import { searchApi } from '@/api/api';
let searchval = ref('')
let searchDate = ref([])
import _ from 'lodash'
watch(searchval, _.debounce((searchval) => {
    searchApi(searchval).then(res => {
        console.log('搜索数据', res)
        searchDate.value = res.data.message
    })
}))
</script>

<style lang="scss" scoped></style>